class ImportService:
    @staticmethod
    def import_from_excel(file_path):
        """从Excel导入数据到数据库"""
        # 导入控件坐标
        coordinates = extract_all_coordinates(file_path)
        for module, controls in coordinates.items():
            module_obj = Module.query.filter_by(name=module).first()
            if not module_obj:
                module_obj = Module(name=module)
                db.session.add(module_obj)
            
            for name, (x, y) in controls.items():
                coord = Coordinate(
                    module=module_obj,
                    element_name=name,
                    x_coord=x,
                    y_coord=y
                )
                db.session.add(coord)
        
        db.session.commit() 